package com.hq.learnmybatisplus.filter;

import com.baomidou.mybatisplus.core.parser.ISqlParserFilter;
import com.baomidou.mybatisplus.core.parser.SqlParserHelper;
import com.hq.learnmybatisplus.config.PaginationInterceptorConfig;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.reflection.MetaObject;


/**
 * 特定sql语句过滤或不过滤配置
 * 或者在@SqlParser注解对应的dao接口进行不过滤处理
 * @author hq
 * @see PaginationInterceptorConfig
 */
public class MySqlParserFilter implements ISqlParserFilter {

    /**
     * @param metaObject
     * @return  false表示不过滤
     */
    @Override
    public boolean doFilter(MetaObject metaObject) {
        //UserDao下面的 selectById mySelectList PaginationInterceptorConfig配置不生效
        MappedStatement mappedStatement = SqlParserHelper.getMappedStatement(metaObject);
        if("com.hq.learnmybatisplus.dao.UserDao.selectById".equals(mappedStatement.getId())){
            return true;
        }
        if("com.hq.learnmybatisplus.dao.UserDao.mySelectList".equals(mappedStatement.getId())){
            return true;
        }
        return false;
    }
}
